package gov.child.web.exception;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 当controller里面有带注解的ExceptionHandler时后屏蔽掉后续的handler
 * @author fzh
 * @since 2017/9/11
 */
public class DefaultExceptionHandler extends ExceptionHandlerExceptionResolver {

    private static Logger logger = LogManager.getLogger(DefaultExceptionHandler.class);

    @Override
    protected ModelAndView doResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod, Exception exception) {
        logger.error("Catch Exception: ", exception);
        return new ModelAndView("notFound");
    }
}
